<?php
if($_POST['page'])
{
$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = 15; // Per page records
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
$productId = $this->getRequest()->getParam('id');
 $model = Mage::getModel('catalog/product'); //getting product model
                $_product = $model->load($productid); //getting product object for particular product id
  $resource = Mage::getSingleton('core/resource');
               $readConnection = $resource->getConnection('core_read');
               $table = $resource->getTableName('catalog/product');
               $table_review_detail= $resource->getTableName('review/review_detail');//get title,detail,nickname, customerid
               $table_review= $resource->getTableName('review/review');//get created on // review_id
               $table_review_status= $resource->getTableName('review/review_status');//get status_code
               $table_review_entity=$resource->getTableName('review/review_entity');//get entity_id, entity_code
               $table_review_store = $resource->getTableName('review/review_store');//get review_id, store_ID
              // $productId = $this->getRequest()->getParam('id');    
                
 $query = "SELECT count(r.review_id), r.review_id,r.created_at,rdt.title,rdt.customer_id, rdt.detail, rdt.nickname,rs.status_code, p.sku FROM " . $table_review . " r join " .$table_review_store .
                  " rvs on r.review_id = rvs.review_id  join " .$table_review_detail. " rdt on r.review_id = rdt.review_id join review_status rs on r.status_id = rs.status_id join ".$table." p on r.entity_pk_value = p.entity_id "                
                  . " WHERE p.entity_id = ". (int)$productid 
                  ." Group By r.review_id "
                  . " Order By r.Review_ID DESC "
                   ." LIMIT ". "$start, $per_page";
             ;
             $getname =$_product->getName();
 $sku = $readConnection->fetchAll($query);
//$result_pag_data = mysql_query($query) or die('MySql Error' . mysql_error());
$msg = "";
$count=0;
foreach ($sku as $row)
{
    $count=$count+1;
     if($row['customer_id'] == null || $row['customer_id']=='')
     {
         $type ='Guest';
     }
     else
     {
         $type ='Customer';
     }
     if($item['customer_id']=='2')
     {
         $type ='Admin';
     }
//$htmlmsg=htmlentities($row['message']); //HTML entries filter
$msg .= "<tr class='even pointer' style='background-color: #F2F2F2;border: 1px solid #303030' >" 
."<tr class='even pointer' style='background-color: #F2F2F2;border: 1px solid #303030' >"
."<td class='a-center' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['review_id']). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['created_at']). "'</td>"
."<td class='a-center' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['status_code']). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['title']). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['nickname']). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['detail']). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($type). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($getname). "'</td>"
."<td class='a-left' style='padding:3px;border: 1px solid #BDBDBD;border-left: 0px;border-right: 0px'> '".htmlentities($row['sku']). "'</td>";
}
$msg="    <table id='productGrid_table' cellspacing='0' class='data' style='-moz-border-radius:10px;-webkit-border-radius:10px;-webkit-box-shadow: 5px 5px 2px #ccc;border: 2px solid #BDBDBD;border-top: 0.1px solid #BDBDBD;' >
                <colgroup>
                        <col width='30'>
                        <col width='150'>
                        <col width='50'>
                        <col width='200'>
                        <col width='100'>
                        <col width='300'>
                        <col width='60'>
                        <col width='100'>
                </colgroup>".
        
        "<thead style=''>
                    <tr style='background: #FFF9E9' class='headings'  >
                        
                        <!--<th><span class='nobr'><a href='#' name='entity_id' title='asc' class='sort-arrow-desc'><span class='sort-title'>ID</span></a></span></th> -->
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;'><span>ID</span></th> 
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;-webkit-box-shadow: 5px 5px 2px #ccc;    '><span class='nobr'><span class='sort-title'>Created On</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px; -webkit-box-shadow: 5px 5px 2px #ccc;   '><span class='nobr'><span class='sort-title'>Status</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;  '><span class='nobr'><span class='sort-title'>Title</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;  '><span class='nobr'><span class='sort-title'>Nickname</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;  '><span class='nobr'><span class='sort-title'>Review</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;  '><span class='nobr'><span class='sort-title'>Type</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;  '><span class='nobr'><span class='sort-title'>Product Name</span></span></th>
                        <th style='padding:5px;font-weight:bold;font-size: 15px;border: 1px solid #BDBDBD;border-left: 0px;-moz-border-radius:10px;-webkit-border-radius:10px;  '><span class='nobr'><span class='sort-title'>Product SKU</span></span></th>
                     </tr>
                </thead>".
        
        " <tbody style='border: 1px solid #BDBDBD'>".$msg."  </tbody>
    </table>";
//$msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data
/* -----Total count--- */
//$query_pag_num = "SELECT COUNT(*) AS count FROM messages"; // Total records
//$result_pag_num = mysql_query($query_pag_num);
//$row = mysql_fetch_array($result_pag_num);
//$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);
/* -----Calculating the starting and endign values for the loop----- */

//Some Code. Available in download script

}
?>